import { Action, Module, YubiModule } from './base';

export interface IUserItem {
  id: number;
  key: string;
  name: string;
}

export interface IUserState {
  userList: IUserItem[];
}

@YubiModule({ name: 'app' })
class UserModule implements Module<IUserState>{
  public state: IUserState = {
    userList: [],
  };

  /**
   * get UserList
   * @param 
   */
  @Action()
  getUser(temp: number) {
    
    return new Promise<boolean>((resolve, reject)=>{
      this.state.userList.push(
        ...[{
          key: '1'+temp,
          id: 1,
          name: '张三',
        },
        {
          key: '2'+temp,
          id: 2,
          name: '李四',
        }]
      )
      setTimeout(() => {
        resolve(true)
      }, 2000);
    })
  }
}

export const userModule = new UserModule();
